import {Descriptions, Modal} from 'antd';
import React from 'react';
import {API} from "@/services/typings";

interface DetailModalProps {
  visible: boolean;
  onClose: () => void;
  data?: API.ISysJobLog;
}

const DetailModal: React.FC<DetailModalProps> = ({ visible, onClose, data }) => {
  return (
    <Modal
      title="任务日志详情"
      width={800}
      open={visible}
      onCancel={onClose}
      footer={null}
      destroyOnClose
    >
      {data && (
        <Descriptions column={1} bordered>
          <Descriptions.Item label="日志ID">{data.jobLogId}</Descriptions.Item>
          <Descriptions.Item label="任务名称">{data.jobName}</Descriptions.Item>
          <Descriptions.Item label="任务组">
            {data.jobGroup === 'SYSTEM' ? '系统' : '默认'}
          </Descriptions.Item>
          <Descriptions.Item label="调用目标">{data.invokeTarget}</Descriptions.Item>
          <Descriptions.Item label="执行状态">
            {data.status === '0' ? (
              <span style={{ color: 'green' }}>成功</span>
            ) : (
              <span style={{ color: 'red' }}>失败</span>
            )}
          </Descriptions.Item>
          <Descriptions.Item label="日志信息">{data.jobMessage}</Descriptions.Item>
          {data.status === '1' && (
            <Descriptions.Item label="异常信息">
              <pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
                {data.exceptionInfo}
              </pre>
            </Descriptions.Item>
          )}
          <Descriptions.Item label="创建时间">{data.createdAt}</Descriptions.Item>
        </Descriptions>
      )}
    </Modal>
  );
};

export default DetailModal;
